package com.lin.cms.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lin.cms.criteria.GroupsCriteria;
import com.lin.cms.dao.GroupsMapper;
import com.lin.cms.domain.Groups;
import com.lin.cms.service.GroupService;
import com.lin.cms.util.Paging;

@Service
public class GroupServiceImpl implements GroupService{
	
	public Groups selectByPrimaryKey(Integer groupId){
		return groupMapper.selectByPrimaryKey(groupId);
	}
	
	public List<Groups> selectByCriteria(GroupsCriteria criteria){
		return groupMapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer groupId){
		int actualRowsAffected = 0;
		
		Groups _oldGroup = groupMapper.selectByPrimaryKey(groupId);
		
		if (_oldGroup != null) {
			actualRowsAffected = groupMapper.deleteByPrimaryKey(groupId);
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(GroupsCriteria criteria){
		int actualRowsAffected = 0;
		
		List<Groups> _oldGroup = groupMapper.selectByCriteria(criteria);
		
		if (_oldGroup.size() != 0) {
			actualRowsAffected = groupMapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(Groups group){
		return groupMapper.insert(group);
	}
	
	public int updateByPrimaryKeySelective(Groups group){
		int actualRowsAffected = 0;
		
		int advertisingId = group.getGroupId();

		Groups _oldGroup = groupMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldGroup != null) {
			actualRowsAffected = groupMapper.updateByPrimaryKeySelective(group);
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(Groups group){
		int actualRowsAffected = 0;
		
		int advertisingId = group.getGroupId();

		Groups _oldGroup = groupMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldGroup != null) {
			actualRowsAffected = groupMapper.updateByPrimaryKey(group);
		}
		
		return actualRowsAffected;
	}
	
	public List<Groups> selectByPage(GroupsCriteria criteria) {
		int totalResults = groupMapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return groupMapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(GroupsCriteria criteria){
		return groupMapper.countByCriteria(criteria);
	}
	
	@Autowired
    private GroupsMapper groupMapper;
}
